﻿
using System;

namespace ProjectIndieFarm
{
    public class GenericChallenge : Challenge
    {
        public override string Name => mName;

        public override bool CheckFinish()
        {
            return mOnCheckFinish.Invoke(this);
        }

        public override void OnFinish()
        {
            mOnFinish?.Invoke(this);
        }

        public override void OnStart()
        {
            mOnStart?.Invoke(this);
        }

        #region ex
        private string mName;

        private Action<GenericChallenge> mOnStart;
        private Func<GenericChallenge, bool> mOnCheckFinish;
        private Action<GenericChallenge> mOnFinish;

        public GenericChallenge SetChallengeName(string name)
        {
            mName = name;
            return this;
        }
        public GenericChallenge OnStart(Action<GenericChallenge> onStart)
        {
            mOnStart = onStart;
            return this;
        }
        public GenericChallenge OnCheckFinish(Func<GenericChallenge, bool> onCheckFInish)
        {
            mOnCheckFinish = onCheckFInish;
            return this;
        }
        public GenericChallenge OnFinish(Action<GenericChallenge> onFinish)
        {
            mOnFinish = onFinish;
            return this;
        }

        public GenericChallenge DisplayNameFactory(Func<string> display)
        {
            mDisplayNameFactory = display;
            return this;
        }

        public void SendMessageWithReward(int reward)
        {
            UIMessageQueue.Push($"挑战[{Name}]完成 金币奖励: <color=#ffd700>${reward}</color>");
        }
        public void SendMessageWithRewardAndOther(int reward, string other)
        {
            UIMessageQueue.Push($"挑战[{Name}]完成 金币奖励: <color=#ffd700>${reward}</color> {other}");
        }

        #endregion 
    }
}
